<?php

include('includes/connect.php');

$user=$_POST['user'];


$count=$_POST['count'];
$user_attempt=1;
for($i=1;$i<=$count;$i++)
	    {

		  $Questions_ID=$_POST["questions".$i];
		  $Options_ID=$_POST["options".$i];
		  
		     $usr=mysql_query("select * from user_attempt where user='".$user."'");
		  	   
			  if(mysql_num_rows($usr)>0)
			  {
				$user_attempt1=	$user_attempt+1;
		  		$u=mysql_query("INSERT INTO user_attempt(`user`,`user_attempt`)VALUES('$user','$user_attempt1')");
				
			  }
			  else {
			  	$u=mysql_query("INSERT INTO user_attempt(`user`,`user_attempt`)VALUES('$user','$user_attempt')");
				   }
		  		if($u)
				{
					$ui=mysql_query("SELECT * FROM user_attempt order by uid desc limit 1");
					$ui_fetch=mysql_fetch_array($ui);
					extract($ui_fetch);
					$uid=$ui_fetch['uid'];
					
					$s=mysql_query("INSERT INTO test_attempted(`uid`,`qid`,`opt_id`)VALUES('$uid','$Questions_ID','$Options_ID')");
				}
		  
	    }		
	
			
		  
	 


/*

foreach($_POST['q'] as $a => $h) 
		 {
		 	$sql="select * from questions where qid='".$h."'";
			$r1=mysql_query($sql);
			$row15=mysql_fetch_array($r1);
			extract($row15);
			$iidd=$row15['qid'].'<br>';
			echo 'ques'.$iidd; 
	
			 
		}
		


//$sql = mysql_query("select * from options where opt_id=".$iidd);


*/



?>